import { useEffect, useState } from "react"

export default function useFetchList(props:any) {
    const [dataSource, setDataSource] = useState([])
    const [total, setTotal] = useState(0)
    const [filterParams, setFilterParams] = useState({ page: 1, size: 3, activityStatus: '', activityName: '' ,...(props.defaultParams || {})})
    useEffect(() => {
        getData()
    }, [filterParams])
    const getData=()=>{
        fetch(props.url, {
            method: "POST",
            body: JSON.stringify(filterParams),
            headers: {
                "Content-Type": "application/json"
            }
        }).then(res => res.json()).then(res => {
            console.log(res)
            const datalist=res.data.list
            datalist.forEach(item => {
                item.key=item.id
            });
            setDataSource(res.data.list)
        })
    }
    return {
        dataSource,
        total,
        filterParams,
        setFilterParams,
        getData
    }
}
